﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;

namespace _180FrameWork.DataBaseHelper
{
    internal class MyParameterMapper : IParameterMapper
    {
        public MyParameterMapper(IDictionary<string, object> p)
        {
            this.paramValues = p;
        }

        public void AssignParameters(DbCommand command, object[] parameterValues)
        {
            foreach (string strPara in paramValues.Keys)
            {
                DbParameter para = command.CreateParameter();
                para.ParameterName = strPara;
                if (paramValues[strPara] != null)
                    para.Value = paramValues[strPara];
                else
                    para.Value = DBNull.Value;
                command.Parameters.Add(para);
            }
        }

        private IDictionary<string, object> paramValues { get; set; }
    }
}
